export const formatLongToStr = (data) => {
    const date = new Date(data);

    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    const hours = date.getHours().toString().padStart(2, '0');
    const minutes = date.getMinutes().toString().padStart(2, '0');
    const seconds = date.getSeconds().toString().padStart(2, '0');

    const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    return formattedDate;
}

export const formatLongToISO = (data) => {
    const date = new Date(data);

    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    const hours = date.getHours().toString().padStart(2, '0');
    const minutes = date.getMinutes().toString().padStart(2, '0');
    const seconds = date.getSeconds().toString().padStart(2, '0');
    const milliseconds = date.getMilliseconds().toString().padStart(3, '0');

    // 获取时区偏移，转换为"+HH:MM"或"-HH:MM"格式
    const timezoneOffset = -date.getTimezoneOffset(); // 得到的是分钟数
    const offsetSign = timezoneOffset >= 0 ? '+' : '-';
    const offsetHours = Math.abs(Math.floor(timezoneOffset / 60)).toString().padStart(2, '0');
    const offsetMinutes = (Math.abs(timezoneOffset) % 60).toString().padStart(2, '0');
    const timezone = `${offsetSign}${offsetHours}:${offsetMinutes}`;

    const formattedDate = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}${timezone}`;
    return formattedDate;
}


export const dateTimeInMilliseconds = (dateTimeString) =>{
    var dateObj = new Date(dateTimeString);
    return dateObj.getTime();
}